package com.xxx.springboot.config;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import com.xxx.springboot.service.impl.NettyClient;
import com.xxx.springboot.service.impl.NettyServer;

/**
 * Netty的配置类
 */
@Configuration
public class NettyConfig {

	@Autowired
	private NettyServer server;

	@Autowired
	private NettyClient client;

	// 加上该注解项目启动时就执行一次该方法（jdk自带）
	@PostConstruct
	public void initMessage() {
		server.run(9502); // 启动netty Server
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		client.run("ws://localhost:" + 9502); // 启动 netty client
	}

}
